package com.kitking.myapplication.utils;

import okhttp3.FormBody;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.RequestBody;

public class okHttpUtil {
    //get请求
    public static void sendOkHttpRequest(String address, okhttp3.Callback callback) {
        OkHttpClient client = new OkHttpClient();
        Request request = new Request.Builder()
                .url(address)
                .build();
        client.newCall(request).enqueue(callback);

    }

    //post请求
    public static void sendOkHttpRequest2(String address,String key,String value, okhttp3.Callback callback) {
        OkHttpClient client = new OkHttpClient();
        //post里的参数函数
        RequestBody requestBody = new FormBody.Builder()
                .add(key,value)
                .build();
        Request request = new Request.Builder()
                .url(address)
                .post(requestBody)
                .build();
        client.newCall(request).enqueue(callback);
    }
}
